const path = require('path')
const fileReader = require('../utils/fileReader')
module.exports = async(ctx, next) => {
    const url = ctx.request.url
    let filePath = url.replace('/api', '')
    filePath = '../data' + filePath + '.json'
    filePath = path.join(__dirname, filePath)
    try {
        const ret = await fileReader.getFileJsonData(filePath)
        ctx.response.body = ret
    }catch(error){
        const errorMsg = {
            message: '读取失败',
            status: 404
        }
        ctx.response.body = JSON.stringify(errorMsg)
    }
}